package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.PmsBatchProduct;
import com.ruoyi.system.service.IPmsBatchProductService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 批次-商品关联Controller
 *
 * @author ruoyi
 * @date 2024-11-28
 */
@RestController
@RequestMapping("/system/product_batch")
public class PmsBatchProductController extends BaseController
{
    @Autowired
    private IPmsBatchProductService pmsBatchProductService;

    /**
     * 查询批次-商品关联列表
     */
    @PreAuthorize("@ss.hasPermi('system:product:list')")
    @GetMapping("/list")
    public TableDataInfo list(PmsBatchProduct pmsBatchProduct)
    {
        startPage();
        List<PmsBatchProduct> list = pmsBatchProductService.selectPmsBatchProductList(pmsBatchProduct);
        return getDataTable(list);
    }

    /**
     * 导出批次-商品关联列表
     */
    @PreAuthorize("@ss.hasPermi('system:product:export')")
    @Log(title = "批次-商品关联", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PmsBatchProduct pmsBatchProduct)
    {
        List<PmsBatchProduct> list = pmsBatchProductService.selectPmsBatchProductList(pmsBatchProduct);
        ExcelUtil<PmsBatchProduct> util = new ExcelUtil<PmsBatchProduct>(PmsBatchProduct.class);
        util.exportExcel(response, list, "批次-商品关联数据");
    }

    /**
     * 获取批次-商品关联详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:product:query')")
    @GetMapping(value = "/{pmsBatchProductId}")
    public AjaxResult getInfo(@PathVariable("pmsBatchProductId") Long pmsBatchProductId)
    {
        return success(pmsBatchProductService.selectPmsBatchProductByPmsBatchProductId(pmsBatchProductId));
    }

    /**
     * 新增批次-商品关联
     */
    @PreAuthorize("@ss.hasPermi('system:product:add')")
    @Log(title = "批次-商品关联", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PmsBatchProduct pmsBatchProduct)
    {
        return toAjax(pmsBatchProductService.insertPmsBatchProduct(pmsBatchProduct));
    }

    /**
     * 修改批次-商品关联
     */
    @PreAuthorize("@ss.hasPermi('system:product:edit')")
    @Log(title = "批次-商品关联", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PmsBatchProduct pmsBatchProduct)
    {
        return toAjax(pmsBatchProductService.updatePmsBatchProduct(pmsBatchProduct));
    }

    /**
     * 删除批次-商品关联
     */
    @PreAuthorize("@ss.hasPermi('system:product:remove')")
    @Log(title = "批次-商品关联", businessType = BusinessType.DELETE)
	@DeleteMapping("/{pmsBatchProductIds}")
    public AjaxResult remove(@PathVariable Long[] pmsBatchProductIds)
    {
        return toAjax(pmsBatchProductService.deletePmsBatchProductByPmsBatchProductIds(pmsBatchProductIds));
    }
}
